import React, { Component } from 'react'
import { Button, } from 'antd'
export default class ButtonTimer extends Component {
    constructor() {
        super();
        this.state = {
            count: -1
        };
    }

    sendMsg = () => {
        this.setState(
            {
                count: 60
            },
            () => {
                this.countdown();
            }
        );
    };

    countdown = () => {
        if (this.state.count < 0) return;
        setTimeout(() => {
            this.setState(
                {
                    count: this.state.count - 1
                },
                () => {
                    this.countdown();
                }
            );
        }, 1000);
    };

    render() {
        const { count, } = this.state;
        //const {shareState, }=this.props;
        return (
            <div style={{textAlign:'center'}}> 
                <Button type='primary' onClick={this.sendMsg} disabled={count >= 0}>
                    {count >= 0 ? `${count}s` : "发送验证码"}
                </Button>

                <div >
                    {this.props.shareState(this.state)}
                </div>
            </div>

        );
    }
}